<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>登入</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="keywords" content="fly,layui,前端社区">
  <meta name="description" content="登录页面">
  
  <link rel="stylesheet" href="/layui/css/layui.css">
  <link rel="stylesheet" href="/layui/css/global.css">
  <script src="/js/jquery-2.1.0.min.js"></script>
<style>
#login_click{margin:32px; height:40px; width: 200px;}
#login_click a
{


	text-decoration:none;
	background:#2f435e;
	color:#f2f2f2;

	padding: 10px 30px 10px 30px;
	font-size:16px;
	font-family: 微软雅黑,宋体,Arial,Helvetica,Verdana,sans-serif;
	font-weight:bold;
	border-radius:3px;

	-webkit-transition:all linear 0.30s;
	-moz-transition:all linear 0.30s;
	transition:all linear 0.30s;

	}
   #login_click a:hover { background:#385f9e; }


	.code
	{
		background-image:url(code.jpg);
		font-family:Arial;
		font-style:italic;
		color:Red;
		border:0;
		padding:2px 3px;
		letter-spacing:3px;
		font-weight:bolder;
			line-height: 38px;
	}
	.unchanged
	{
		border:0;
	}
</style>
</head>
<body onLoad="createCode()">


<div class="layui-container fly-marginTop">
  <div class="fly-panel fly-panel-user" pad20>
    <div class="layui-tab layui-tab-brief" lay-filter="user">
      <ul class="layui-tab-title">
        <li class="layui-this">登入</li>

      </ul>
      <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
        <div class="layui-tab-item layui-show">
          <div class="layui-form layui-form-pane">
            <form method="post">
              <div class="layui-form-item">
                <label for="L_username" class="layui-form-label">账号</label>
                <div class="layui-input-inline">
                  <input type="text" id="L_username" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label for="L_pass" class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                  <input type="password" id="L_pass" name="pass" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
              </div>

              <div class="">
                	<div id="login_click">
                    <a id="btlogin" onclick="submitForm()">立即登录</a>
                    </div>

              </div>

            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>


<script src="/layui/layui.js"></script>
 <script language="javascript" type="text/javascript">

     var code ; //在全局 定义验证码
     function createCode()
     {
       code = "";
       var codeLength = 4;//验证码的长度
       var checkCode = document.getElementById("checkCode");
       var selectChar = new Array(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');//所有候选组成验证码的字符，当然也可以用中文的
       for(var i=0;i<codeLength;i++)
       {
        var charIndex = Math.floor(Math.random()*36);
        code +=selectChar[charIndex];
       }
       if(checkCode)
       {
         checkCode.className="code";
         checkCode.value = code;
         checkCode.blur();
       }
     }
	</script>

	<script>
$(document).ready(function() {
	//回车提交事件
	$("body").bind('keydown', function(event) {
		if(event.keyCode==13){
			//alert('回车');
			submitForm();
		}
	});
});
</script>

<script>
function submitForm() {

	  // var inputCode = document.getElementById("validCode").value;
			 var L_username = $("#L_username").val();//获取表单的输入值;
			 var L_pass = $("#L_pass").val();//获取表单的输入值;

					//post提交数据开始
						 $.post('/user/login',
						 		{'_token':'{{csrf_token()}}','L_username':L_username,'L_pass':L_pass},
						 		function(data){
						 			// console.log(data);
						 			if(data.status == 0){
						 				layer.msg(data.msg,{icon:6},function(){
						 					// location.reload();
                                            self.location.href="/user/index";
						 				});
						 			}else{
						 				layer.msg(data.msg,{icon:5});
						 			}
						 })
         //                 $.ajax({
							  // //几个参数需要注意一下
								 //  type: "POST",//方法类型
								 //  dataType: "json",//预期服务器返回的数据类型
								 //  url: "../php/login.php" ,//url
								 //  data: {"L_username":L_username,"L_pass":L_pass},//提交的数据
								 //  success: function(res){
									//   if (res.code == 0){  //修改成功
									// 		layui.use('layer', function(){
									// 		layer.msg("登录成功");
									// 		self.location.href="./index.html";
									// 									});
									//   }else {
									// 	layer.msg(data.msg,{icon:5});

									// 	}
									// 				   }

							  // });   	//post提交数据结束

}
</script>
</body>
</html>
